﻿{include file="common/_meta" /}

<title>新建网站角色 - 管理员管理 - H-ui.admin v3.1</title>
<meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-role-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder=""  name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>备注：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="" name="desc">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>网站角色：</label>
			<div class="formControls col-xs-8 col-sm-9">
				
					{volist name="rules" id="vol"}
						<dl class="permission-list">
						<dt>
						<label>
							<input type="checkbox" value="{$vol['id']}" name="ftitle[]" id="ftitle">
							{$vol['title']}</label>
						</dt>
					{volist name="vol['pid_rule']" id="item"}
						<dd>
						
							 <dl class="cl permission-list2">
								<dt>
									<label class="">
										<input type="checkbox" value="{$item['id']}" name="ftitle[]" >
										{$item['title']}</label>
								</dt>
					
					{volist name="item['tid_rule']" id="k"}
								<dd>
									<label class="">
									<input type="checkbox" value="{$k['id']}" name="ftitle[]" >
									{$k['title']}</label>
								</dd>
					{/volist}

							</dl>
					
							
						
						</dd>
					{/volist}
					
						</dl>
					{/volist}
					
				
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<a class="btn btn-success radius" onclick="ajaxsubmit();"> 确定</a>
			</div>
		</div>
	</form>
</article>

{include file="common/_footer" /}

<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript">
$(function(){
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});
});

function ajaxsubmit(){
		$.ajax({
			type:'post',
			url:'{:url('admin/admin/role_add')}',
			dataType:'json',
			data: $('#form-role-add').serialize(),
			success: function(data){
				if(data.code != 200){
					layer.alert(data.msg, {icon: data.icon});
				}else{
					layer.msg(data.msg,{icon:data.icon,time:1000},function(){
					window.parent.location.reload();
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
					});
				}
			},
            error: function(XmlHttpRequest, textStatus, errorThrown){
            	console.log(XmlHttpRequest, textStatus, errorThrown);
				layer.alert('添加失败!', {icon: 2});
			}
		});
	}
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>